/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.frm.bpm.session;

import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import merlion.frm.bpm.entity.CustomerPaymentRecord;
import merlion.frm.bpm.entity.Invoice;
import merlion.frm.bpm.entity.SupplierInvoice;
import merlion.frm.bpm.entity.SupplierPaymentRecord;

/**
 *
 * @author Kenn
 */
@Stateless
public class FinancialStatusSessionBean implements FinancialStatusSessionBeanLocal {

    @PersistenceContext
    private EntityManager em;
    
    @Override
    public Collection<Invoice> getAllInvoice(){
        return em.createQuery("SELECT i FROM Invoice i ORDER BY i.invoiceDate DESC").getResultList();
    }
    
    @Override
    public Collection<Invoice> getAllPaidInvoice(){
        return em.createQuery("SELECT i FROM Invoice i WHERE i.customerPaymentRecord IS NOT NULL").getResultList();
    }
    
    @Override
    public Collection<Invoice> getAllUnpaidInvoice(){
        return em.createQuery("SELECT i FROM Invoice i WHERE i.customerPaymentRecord IS NULL").getResultList();
    }
    
    @Override
    public Collection<SupplierInvoice> getAllSupplierInvoice(){
        return em.createQuery("SELECT s FROM SupplierInvoice s ORDER BY s.dateCreated DESC").getResultList();
    }
    
    @Override
    public Collection<SupplierInvoice> getAllPaidSupplierInvoice(){
        return em.createQuery("SELECT s FROM SupplierInvoice s WHERE s.supplierPaymentRecord IS NOT NULL").getResultList();
    }
    
    @Override
    public Collection<SupplierInvoice> getAllUnpaidSupplierInvoice(){
        return em.createQuery("SELECT s FROM SupplierInvoice s WHERE s.supplierPaymentRecord IS NULL").getResultList();
    }
    
    @Override
    public Collection<CustomerPaymentRecord> getAllCustomerPaymentRecord(){
        return em.createQuery("SELECT c FROM CustomerPaymentRecord c").getResultList();
    }
    
    @Override
    public Collection<SupplierPaymentRecord> getAllSupplierPaymentRecord(){
        return em.createQuery("SELECT s FROM SupplierPaymentRecord s").getResultList();
    }
}
